//% color="#9370DB" iconWidth=50 iconHeight=40
namespace matplotlib_pro{
    //% block="初始化matplotlib模块" blockType="command"
    export function matplotlib_Iint(parameter: any, block: any) {
 
        Generator.addImport(`from matplotlib import pyplot as plt`)

    }
    //% block="设置图表[TOOL]工具栏" blockType="command"
    //% TOOL.shadow="dropdown" TOOL.options="TOOL"
    export function matplotlib_Iinttool(parameter: any, block: any) {
        let tool=parameter.TOOL.code;

        if(`${tool}` === '1'){
            Generator.addCode(`plt.rcParams['toolbar'] = 'None'`)
        }else if(`${tool}` === '2'){
            Generator.addImport(``)
        }   
    }     
    //% block="设置图表显示字体[FONT]" blockType="command"
    //% FONT.shadow="string" FONT.defl="HYQiHei"
    export function matplotlib_Iintfont(parameter: any, block: any) {
        let font=parameter.FONT.code;

        Generator.addCode(`plt.rcParams['font.sans-serif']=[${font}]`)
        
    }
    //% block="设置图表显示字体大小[SIZE]" blockType="command"
    //% SIZE.shadow="number" SIZE.defl="5"
    export function matplotlib_Iintfontsize(parameter: any, block: any) {
        let size=parameter.SIZE.code;

        Generator.addCode(`plt.rcParams['font.size'] = ${size} `)
        
    }

    //% block="创建画图区域宽[WIDE]高[HIGH]并返回画布对象[FIG]轴对象[AX]" blockType="command"
    //% WIDE.shadow="number" WIDE.defl="240"
    //% HIGH.shadow="number" HIGH.defl="320"
    //% FIG.shadow="normal" FIG.defl="fig"
    //% AX.shadow="normal" AX.defl="axes"
    export function matplotlib_Iintcanvas(parameter: any, block: any) {
        let wide=parameter.WIDE.code;
        let high=parameter.HIGH.code;
        let fig=parameter.FIG.code;
        let ax=parameter.AX.code;

        Generator.addCode(`${fig}, ${ax} = plt.subplots(1,1,figsize=(${wide}/100,${high}/100))`)
        
    } 
    //% block="绘制图像横轴[XZ]纵轴[YZ]标签[LAB]" blockType="command"
    //% XZ.shadow="normal"   XZ.defl="x"
    //% YZ.shadow="normal"   YZ.defl="y"
    //% LAB.shadow="normal"   LAB.defl="label"
    export function plt_draw(parameter: any, block: any){ 
        let xz = parameter.XZ.code
        let yz = parameter.YZ.code
        let lab = parameter.LAB.code
        Generator.addCode(`plt.plot(${xz},${yz},label='${lab}')`);
   }

    //% block="对象名[OBJECT]标题[TX]字体大小[SIZE]颜色[COLOR] " blockType="command"
    //% OBJECT.shadow="normal" OBJECT.defl='axes'
    //% TX.shadow="string" TX.defl='标题内容'
    //% COLOR.shadow="dropdown" COLOR.options="COLOR"
    //% SIZE.shadow="string" SIZE.defl="10"
    export function matplotlib_title(parameter: any, block: any) {
        let object=parameter.OBJECT.code;
        let tx=parameter.TX.code;
        let color=parameter.COLOR.code;  
        let size=parameter.SIZE.code;  

        Generator.addCode(`${object}.set_title(${tx},color='${color}',size=${size})`)
        
    }
    //% block="对象名[OBJECT]设置[LABEL]显示标签[TXET]字体大小[SIZE]颜色[COLOR]" blockType="command"
    //% OBJECT.shadow="normal" OBJECT.defl='axes'
    //% LABEL.shadow="dropdown" LABEL.options="LABEL"
    //% TXET.shadow="string" TXET.defl="X轴"
    //% SIZE.shadow="number" SIZE.defl="10"
    //% COLOR.shadow="dropdown" COLOR.options="COLOR"
    export function matplotlib_label(parameter: any, block: any) {
        let object=parameter.OBJECT.code;
        let label=parameter.LABEL.code;
        let text=parameter.TXET.code;
        let size=parameter.SIZE.code;
        let color=parameter.COLOR.code;
        Generator.addCode(`${object}.set_${label}(${text},color='${color}', fontsize=${size})`)
    }   

     //% block="绘制散点图X轴[X]Y轴[Y]显示大小[SIZE]形状[MARK]颜色[COLOR]图例标签[TX]" blockType="command"
    //% X.shadow="list" X.defl="'数据1','数据2'"
    //% Y.shadow="list" Y.defl="'数据1','数据2'"
    //% SIZE.shadow="number" SIZE.defl="10"
    //% MARK.shadow="string" MARK.defl="o"
    //% COLOR.shadow="dropdown" COLOR.options="COLOR"
    //% TX.shadow="string" TX.defl="图例标签"
    export function matplotlib_scatter(parameter: any, block: any) {
        let x=parameter.X.code;
        let y=parameter.Y.code;        
        let size=parameter.SIZE.code;
        let mark=parameter.MARK.code;
        let color=parameter.COLOR.code;
        let tx=parameter.TX.code;

        Generator.addCode(`plt.scatter(${x}, ${y}, color = '${color}',alpha = 0.6,marker = ${mark},s = ${size},label=${tx})`)
    }    
    
    //% block="---"
    export function noteSep1() {
    }

    //% block="显示图例" blockType="command"
    export function matplotlib_Iintshowlegend(parameter: any, block: any) {
     
        Generator.addCode(`plt.legend()`)
        
    }

    //% block="绘制辅助线" blockType="command"
    export function grid(parameter: any, block: any){ 
        Generator.addCode(`plt.grid()`);
   
   }
    //% block="隐藏[XY]刻度" blockType="command"
    //% XY.shadow="dropdown" XY.options="XY"
    export function matplotlib_IintshowXY(parameter: any, block: any) {
        let xy=parameter.XY.code; 
        Generator.addCode(`plt.${xy}ticks([])`)
        
    }
    //% block="显示图像" blockType="command"
    export function matplotlib_Iintshow(parameter: any, block: any) {

        Generator.addCode(`plt.show()`)
        
    }
    //% block="图像保存为[IMG1]" blockType="command"
    //% IMG1.shadow="normal"   IMG1.defl="photoname.png"
    export function plt_save(parameter: any, block: any){ 
        let img1 = parameter.IMG1.code
        Generator.addCode(`plt.savefig('${img1}')`);

   }
}
